import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 新型写法 类似setup
export const useCounterStoreSet = defineStore(
  "counterSet",
  () => {
    const num = ref(50);
    const getDbNum = computed(() => {
      return num.value * 2;
    });
    const add = () => {
      num.value++;
    };
    const minus = () => {
      num.value--;
    };
    return {
      num,
      getDbNum,
      add,
      minus,
    };
  },
    {
      persist: {
        enabled: true,
        strategies: [
          {
            key: "counterSet", //设置存储的key
            storage: localStorage, //表示存储在localStorage
            paths: ["num"], //指定要长久化的字段
          },
        ],
      },
    }
);
